ProfileHeader.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. "use client";
  2. import { UserInfoRep, UserVipInfo, Wallet } from "@/api/user";
  3. import TipsModal, { ModalProps } from "@/components/TipsModal";
  4. import { Link, useRouter } from "@/i18n/routing";
  5. import { useWalletStore } from "@/stores/useWalletStore";
  6. import { WalletEnum } from "@/types";
  7. import { vipImages } from "@/utils/constant";
  8. import { flatPoint, percentage } from "@/utils/methods";
  9. import { ProgressBar, Toast } from "antd-mobile";
  10. import { useTranslations } from "next-intl";
  11. import Image from "next/image";
  12. import { Fragment, useRef, useState } from "react";
  13. type Props = {
  14. userInfo: UserInfoRep;
  15. userMoney: Wallet;
  16. userVip: UserVipInfo;
  17. };
  18. const VipCard = (props: { userVip: UserVipInfo }) => {
  19. const { userVip } = props;
  20. const t = useTranslations("ProfilePage");
  21. // Vip 图标
  22. const vipIconElement = vipImages.map((item, index) => {
  23. if (item.leve === userVip.vip_level) {
  24. return (
  25. <Fragment key={index}>
  26. <Image src={item.src} alt={"vip"} height={110} width={100} />
  27. <span className={"icon-level"} style={{ color: item.color }}>
  28. {item.leve}
  29. </span>
  30. </Fragment>
  31. );
  32. }
  33. });
  34. return (
  35. <div className={"vip-card"}>
  36. <div className={"vip-card__icon"}>{vipIconElement}</div>
  37. <div className={"vip-card-process"}>
  38. {/*<div className={"process-top"}>{userVip.vip_exp}xp</div>*/}
  39. <div>
  40. <ProgressBar
  41. percent={percentage(userVip.vip_exp, userVip.vip_score_exp)}
  42. style={{
  43. "--fill-color": "#fb8b05",
  44. "--track-width": "0.0694rem",
  45. }}
  46. />
  47. </div>
  48. <div className={"process-bottom"}>
  49. <span>VIP{userVip.vip_level}</span>
  50. <span className={"process-bottom-desc"}>
  51. {t("expTips", {
  52. exp: flatPoint(userVip.vip_score_exp - userVip.vip_exp),
  53. })}
  54. </span>
  55. <span>
  56. VIP
  57. {userVip.vip_next_level}
  58. </span>
  59. </div>
  60. </div>
  61. </div>
  62. );
  63. };
  64. const Progress = (props: { percent: number }) => {
  65. const { percent } = props;
  66. return (
  67. <div className="flex">
  68. <ProgressBar
  69. percent={percent}
  70. className={"mr-[0.0694rem] flex-1"}
  71. style={{
  72. "--fill-color": "var(--primary-color)",
  73. "--track-width": "0.0694rem",
  74. }}
  75. />
  76. <span className={"text-primary-color"}>{percent}%</span>
  77. </div>
  78. );
  79. };
  80. const WalletContent = (props: {
  81. percentage: number;
  82. type: string;
  83. difference: number;
  84. current: number;
  85. }) => {
  86. const { percentage, type, difference, current } = props;
  87. const t = useTranslations("ProfilePage");
  88. return (
  89. <div>
  90. <div className={"mb-[0.12rem] text-[0.12rem]"}>
  91. <span className={"mr-[10px]"}>{type}</span>
  92. <i className={"mr-[10px] indent-[10px] text-[0.1528rem] font-bold"}>R$</i>
  93. <span>{current}</span>
  94. </div>
  95. <Progress percent={percentage} />
  96. <div>
  97. <span>{t("modalBottomTips")}</span>
  98. <span>{difference.toFixed(2)}</span>
  99. </div>
  100. </div>
  101. );
  102. };
  103. // 现金
  104. const BalanceContent = (props: { wallet: Wallet }) => {
  105. const { wallet } = props;
  106. const t = useTranslations("ProfilePage");
  107. return (
  108. <>
  109. <WalletContent
  110. difference={wallet.target_score_rollover - wallet.current_score_rollover}
  111. type={t("balance")}
  112. current={wallet.score || 0}
  113. percentage={percentage(wallet.current_score_rollover, wallet.target_score_rollover)}
  114. />
  115. </>
  116. );
  117. };
  118. const BonusContent = (props: { wallet: Wallet }) => {
  119. const { wallet } = props;
  120. const t = useTranslations("ProfilePage");
  121. return (
  122. <div>
  123. <WalletContent
  124. difference={wallet.target_point_rollover - wallet.current_point_rollover}
  125. type={t("bonus")}
  126. current={wallet.point || 0}
  127. percentage={percentage(wallet.current_point_rollover, wallet.target_point_rollover)}
  128. />
  129. <p className={"text-center"}>{t("bonusArticle")}</p>
  130. <ul className={"ml-[0.1389rem] list-decimal text-[0.12rem] text-[#666]"}>
  131. <li>{t("bonusDesc1")}</li>
  132. <li>{t("bonusDesc2")}</li>
  133. <li>{t("bonusDesc3")}</li>
  134. </ul>
  135. </div>
  136. );
  137. };
  138. const FreeContent = (props: { wallet: Wallet }) => {
  139. const { wallet } = props;
  140. const t = useTranslations("ProfilePage");
  141. return (
  142. <div>
  143. <WalletContent
  144. difference={wallet.target_free_score_rollover - wallet.current_free_score_rollover}
  145. type={t("free")}
  146. current={wallet.free_score || 0}
  147. percentage={percentage(
  148. wallet.current_free_score_rollover,
  149. wallet.target_free_score_rollover
  150. )}
  151. />
  152. <p className={"text-center"}>{t("freeArticle")}</p>
  153. <ul className={"ml-[0.1389rem] list-decimal text-[0.12rem] text-[#666]"}>
  154. <li>{t("freeDesc1")}</li>
  155. <li>{t("freeDesc2")}</li>
  156. </ul>
  157. </div>
  158. );
  159. };
  160. const ReplayContent = (props: { wallet: Wallet }) => {
  161. const { wallet } = props;
  162. const t = useTranslations("ProfilePage");
  163. return (
  164. <div>
  165. <WalletContent
  166. difference={wallet.target_lose_score_rollover - wallet.current_lose_score_rollover}
  167. type={t("replay")}
  168. current={wallet.lose_score || 0}
  169. percentage={percentage(
  170. wallet.current_lose_score_rollover,
  171. wallet.target_lose_score_rollover
  172. )}
  173. />
  174. <p className={"text-center"}>{t("replayArticle")}</p>
  175. <ul className={"ml-[0.1389rem] list-decimal text-[0.12rem] text-[#666]"}>
  176. <li>{t("replayDesc1")}</li>
  177. <li>{t("replayDesc2")}</li>
  178. </ul>
  179. </div>
  180. );
  181. };
  182. const WalletCard = (props: { userMoney: Wallet }) => {
  183. const { userMoney } = props;
  184. const t = useTranslations("ProfilePage");
  185. const tipsRef = useRef<ModalProps>(null);
  186. const [tipsStatus, setTipsStatus] = useState<keyof typeof WalletEnum>("Bonus");
  187. const modalHandler = (key: keyof typeof WalletEnum) => {
  188. setTipsStatus(key);
  189. tipsRef.current?.onOpen();
  190. };
  191. return (
  192. <>
  193. <TipsModal
  194. ref={tipsRef}
  195. title={
  196. <div className={"flex items-center"}>
  197. <i
  198. className={"iconfont icon-liwuhuodong mr-[0.0694rem] text-[0.2778rem]"}
  199. ></i>
  200. {t("modalTitle")}
  201. </div>
  202. }
  203. >
  204. {/*现金*/}
  205. {tipsStatus === WalletEnum.Balance ? <BalanceContent wallet={userMoney} /> : null}
  206. {/* 彩金*/}
  207. {tipsStatus === WalletEnum.Bonus ? <BonusContent wallet={userMoney} /> : null}
  208. {/* 免费币 */}
  209. {tipsStatus === WalletEnum.Free ? <FreeContent wallet={userMoney} /> : null}
  210. {/* 重玩币 */}
  211. {tipsStatus === WalletEnum.Replay ? <ReplayContent wallet={userMoney} /> : null}
  212. </TipsModal>
  213. <div className="coin">
  214. <span className="coin_left__icon iconfont icon-icon-wallet"></span>
  215. <div className={"coin_right_wallet"}>
  216. <div
  217. className={"wallet_left_border"}
  218. onClick={() => modalHandler(WalletEnum.Balance)}
  219. >
  220. <div className={"wallet_header"}>
  221. <span>{t("balance")}</span>
  222. <Image
  223. className="wallet_header__icon"
  224. src="/img/a.png"
  225. alt="question"
  226. width={15}
  227. height={15}
  228. />
  229. </div>
  230. <div className="num">
  231. <span className="uppercase">brl </span>
  232. <span>{userMoney.score || 0.0}</span>
  233. </div>
  234. </div>
  235. <div
  236. className={"wallet_right_content"}
  237. onClick={() => modalHandler(WalletEnum.Bonus)}
  238. >
  239. <div className={"wallet_header"}>
  240. {t("bonus")}
  241. <Image
  242. className="wallet_header__icon"
  243. src="/img/a.png"
  244. alt="question"
  245. width={15}
  246. height={15}
  247. />
  248. </div>
  249. <div className="num">
  250. <span className="uppercase">brl </span>
  251. <span>{userMoney.point || 0.0}</span>
  252. </div>
  253. </div>
  254. <div
  255. className={"wallet_left_border"}
  256. onClick={() => modalHandler(WalletEnum.Free)}
  257. >
  258. <div className={"wallet_header"}>
  259. {t("free")}
  260. <Image
  261. className="wallet_header__icon"
  262. src="/img/a.png"
  263. alt="question"
  264. width={15}
  265. height={15}
  266. />
  267. </div>
  268. <div className="num">
  269. <span className="uppercase">brl </span>
  270. <span>{userMoney.free_score || 0.0}</span>
  271. </div>
  272. </div>
  273. <div
  274. className={"wallet_right_content"}
  275. onClick={() => modalHandler(WalletEnum.Replay)}
  276. >
  277. <div className={"wallet_header"}>
  278. {t("replay")}
  279. <Image
  280. className="wallet_header__icon"
  281. src="/img/a.png"
  282. alt="question"
  283. width={15}
  284. height={15}
  285. />
  286. </div>
  287. <div className="num">
  288. <span className="uppercase">brl </span>
  289. <span>{userMoney.lose_score || 0.0}</span>
  290. </div>
  291. </div>
  292. </div>
  293. </div>
  294. </>
  295. );
  296. };
  297. export const ProfileHeader = (props: Props) => {
  298. const { userInfo, userVip } = props;
  299. const t = useTranslations("ProfilePage");
  300. const wallet = useWalletStore((state) => state.wallet);
  301. const router = useRouter();
  302. const handler = () => {
  303. if (!!wallet.score) {
  304. router.push("/withdraw");
  305. } else {
  306. Toast.show("no money ");
  307. }
  308. };
  309. return (
  310. <>
  311. <div className={"userContent"}>
  312. <div className={"userInfo"}>
  313. <div>
  314. <div className={"bgImg"}>
  315. <Image
  316. src={"/img/avatar.png"}
  317. className={"h-[100%] w-[100%]"}
  318. alt={"avatar"}
  319. width={120}
  320. height={120}
  321. />
  322. </div>
  323. <div>
  324. <span>{t("Conta")}</span>
  325. <span className="phone">{userInfo?.user_phone || ""}</span>
  326. </div>
  327. </div>
  328. <Link className="goto iconfont icon-xiangzuo1" href={`/changePassword`}></Link>
  329. </div>
  330. {/*vipcard*/}
  331. <VipCard userVip={userVip} />
  332. <WalletCard userMoney={wallet} />
  333. </div>
  334. <div className="link">
  335. <Link href={"/deposit"} className={"btn"}>
  336. {t("Depósito")}
  337. </Link>
  338. <p className={"btn"} onClick={handler}>
  339. {t("Sacar")}
  340. </p>
  341. </div>
  342. </>
  343. );
  344. };